package eagle.im.client;

import eagle.im.proto.LoginModel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Program : eagle-im
 * @ClassName : ClientHandler
 * @Description :
 * @Date: 2021-12-20 18:59
 * @Version : 1.0
 */
public class ClientHandler extends SimpleChannelInboundHandler<LoginModel.LoginInfo> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LoginModel.LoginInfo msg) throws Exception {

        System.out.println( "name:   " +msg.getName());
        System.out.println(" address : " + msg.getDesc());
        System.out.println("  age: " +msg.getType());
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        //客户端创建连接之后就像服务端发送消息
        LoginModel.LoginInfo student = LoginModel.LoginInfo.newBuilder()
                .setName("张三")
                .setPassword("bbbbbbbbbbbbbbbbbbbbbbbbbb")
                .setDesc("合肥dddddddddddddddddddddddddddddddddddddd")
                .setType(1)
                .build();

        ctx.writeAndFlush(student);
    }

}
